package Binrary_Management_System.ioPeration;

import Binrary_Management_System.Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 何华树
 * Date: 2024-09-13
 * Time: 14:05
 */
public class ReturnOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书！");

        int currentSize = bookList.getUseSize();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要归还的书的书名：");
        String name = scanner.nextLine();
        for (int i = 0; i < currentSize; i++) {
            if(bookList.getBook(i).getName().equals(name)) {
                if(bookList.getBook(i).isBorrowed() == true) {
                    bookList.getBook(i).setBorrowed(false);
                    System.out.println("归还成功！");
                    return;
                }else {
                    System.out.println("这本书没有被借出，归还操作错误！");
                    return;
                }
            }
        }
        System.out.println("没有你要归还的图书！");
    }
}
